<template>
  <div class="wechat-config">
        <div class="config-list">
          <div class="channel-up">
            <div class="channel-up-title">
              <span>通道配置</span>
            </div>
            <div class="channel-up-content">
              <img src="../../../../../static/img/ofc_icon.png" alt="加载失败"/>
              <span id="span-channel-1">官方通道</span><span id="span-channel-2">(已配置)</span><pre/>
              <span id="span-channel-3" style="cursor: pointer;" @click="parameterConfiguration">参数配置</span>
              <!-- <span style="cursor: pointer;" id="span-channel-4" @click="rateConfiguration">费率配置</span> -->
            </div>
          </div>
        </div>
        
    <div class="official-model" v-if="model">
      <!--微信参数配置-->
      <div class="official-wechat-configuration" v-if="wechatParameter">
        <div class="off-con-title">
          <span>官方通道参数配置</span>
          <i class="el-icon-close" @click="close"></i>
        </div>
        <div class="off-con-content">
          <el-form label-width="130px">
            <!-- <el-form-item class="off-con-list" label="appid">
              <el-input style="width:65%" type="password" v-model="config.appid" clearable placeholder="appid"></el-input>
            </el-form-item> -->
            <el-form-item class="off-con-list" label="微信子商户号">
              <el-input style="width:65%" type="password" v-model="config.partner" placeholder="微信子商户号"></el-input>
            </el-form-item>
            <el-form-item class="off-con-list" label="微信key">
              <el-input style="width:65%" type="password" v-model="config.weixinKey" clearable placeholder="微信key"></el-input>
            </el-form-item>
          </el-form>
        </div>
        <div class="off-con-button">
          <el-button type="primary" @click="handleAuth">校验授权</el-button>
          <el-button type="primary" @click="handleSubmit" >提交</el-button>
          <el-button type="warning" @click="close">关闭</el-button>
        </div>
      </div>
      <!--微信费率配置-->
      <div class="official-wechat-rate" v-if="wechatRate">
        <div class="off-con-title">
          <span>官方通道费率</span>
          <i class="el-icon-close" @click="close"></i>
        </div>
        <div class="off-con-content">
          费率配置
        </div>
        <div class="off-con-button">
          <el-button type="primary">提交</el-button>
          <el-button type="warning" @click="close">关闭</el-button>
        </div>
      </div>
      <!--微信配置-->
      <div class="weChat-model" v-if="wechatConfiguration">
        <div class="off-con-title">
          <span>微信刷卡支付配置</span>
          <i class="el-icon-close" @click="close"></i>
        </div>
        <div class="off-con-content">
          默认官方通道
          <!-- <el-form label-width="130px">
            <el-form-item class="off-rate-list" label="选择通道">
              <el-select v-model="value4" style="width:65%" clearable placeholder="请选择">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-form> -->
        </div>
        <div class="off-con-button">
          <el-button type="primary">提交</el-button>
          <el-button type="warning" @click="close">关闭</el-button>
        </div>
      </div>
    </div>

        <div class="container-down">
          <div class="weChat-pay-down">
            <div class="weChat-pay-title">微信支付配置</div>
            <div class="">
              <table border="0" cellspacing="0">
                <thead>
                  <tr>
                    <th><div class="table-cell">名称</div></th>
                    <th><div class="table-cell">支付通道</div></th>
                    <th><div class="table-cell">支付费率</div></th>
                    <th><div class="table-cell">结算周期</div></th>
                    <th><div class="table-cell">操作</div></th>
                  </tr>
                </thead>
                <tbody>
                  <tr  v-for="(cell,index) in typeList" :key="index">
                    <td><div class="table-cell"></div></td>
                    <td><div class="table-cell"></div></td>
                    <td><div class="table-cell"></div></td>
                    <td><div class="table-cell"></div></td>
                    <td><div class="table-cell"><span id="span-channel-3" style="cursor: pointer;" @click="weChatPayModel">配置</span></div></td>
                  </tr>
                </tbody>
              </table>
            </div>
          </div>
        </div>

  </div>
</template>

<script>
export default {
  name:'wechat-config',
  data () {
    return {
        channelRate:"",
        config:{
          id:"",
          // appid:"",
          weixinKey:"",
          partner:"",
          shopId:""
        },
        wxTypeList:[
          {value:"1",label:"官方"}
        ],
        shopTypeList:[
          {value:"1",label:"独立商户"},
          {value:"2",label:"子商户"}
        ],
        typeList:[],
        model:false,
        wechatParameter:false,
        wechatRate:false,
        wechatConfiguration:false,
    };
  },
  props:{
      shopId:{
          type:String,
          default:function(){
              return 0
          }
      }
  },
  created() {
      this.config.shopId = this.shopId;
  },
  mounted() {},
  methods: {
    initConfig(){
      let url = `paymentchannel/weixin/query?shopId=${this.shopId}`;
      this.$Http.get(url).then(res=>{
      
         if(res.data.resp_code ==='000000'){
           // 成功；
           if(res.data.result){
	           	for(let key in this.config){
	              this.config[key] = res.data.result[key];
	            }
           }  
         }else{
           this.$notify.error({
                title: '温馨提示',
                message: res.data.resp_message
            });
         }
      }).catch(err=>{
          this.$notify.error({
                title: '错误',
                message: '配置失败！服务器繁忙！'
            });
      })

    },
    //参数配置
    parameterConfiguration(){
      this.model=true;
      this.wechatParameter=true;
       this.initConfig();
    },
    //费率配置
    rateConfiguration(){
      this.model=true;
      this.wechatRate=true;
    },
    //配置
    weChatPayModel(){
      this.model=true;
      this.wechatConfiguration=true;
    },
    //关闭
    close(){
      this.model=false;//透明背景
      this.wechatParameter=false;
      this.wechatRate=false;
      this.wechatConfiguration=false;
    },
    handleAuth(){
      let token = sessionStorage.getItem(1);
      let url = `paymentchannel/wechat/supply/${token}`;
      let params = 'shopId=' + this.shopId;
      this.$Http.post(url,params).then(res=>{
        if(res.data.resp_code === "000000"){
          this.model=false;
          this.wechatParameter=false;
          this.$message.success("配置成功！");
        }else{
          this.$message.error("配置操作失败！请联系管理员！");
        }
      }).catch(err=>{
          this.$message.error("服务器繁忙！无法验证！");
      })
    },
    handleSubmit(){
       // 提交配置信息
       let token = sessionStorage.getItem(1);
       let url = `paymentchannel/weixin/configure/${token}`;  
       let l = [];
       if(this.config.id===''||this.config.id===null){
        this.config.id = 0;
      }
       for(let key in this.config){
         l.push(key+'='+this.config[key])
       }
       let params = l.join('&');
       params=encodeURI(params);
       this.$Http.post(url,params).then(res=>{
         if(res.data.resp_code === '000000'){
            // 成功
            this.$message.success("修改成功！");
            this.close();
         }else{
           this.$notify.error({
                title: '温馨提示',
                message: res.data.resp_message
            });
         }
       }).catch(err=>{
          this.$notify.error({
                title: '错误',
                message: '配置失败！服务器繁忙！'
            });
       })
    }
  }
}

</script>
<style scoped>
.channel-up{
  width: 100%;
  height: 125px;
}
.channel-up-title{
  height: 50px;
  line-height: 50px;
  font-size: 20px;
  color: rgb(139, 136, 136);
  padding: 7px 0 0 20px;
}
.channel-up-content>img{
  width: 50px;
  height: 50px;
  float: left;
  padding: 3px 5px 5px 20px;
}
.container-down{
  border: 1px solid #ededed;
  margin-top: 10px;
}
.weChat-pay-title{
  height: 50px;
  line-height: 50px;
  font-size: 20px;
  color: rgb(139, 136, 136);
  padding: 7px 0 0 20px;
}
.official-model{
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  background-color:rgba(71, 68, 68, 0.438)
}
.official-wechat-configuration{
  width: 550px;
  position: absolute;
  top: 10%;
  left: 35%;
  border-radius: 1%;
  background-color: #F5F7FA
}
.off-rate-list{
  height: 70px;
  padding: 20px 0 0 12%;
  border-bottom: #dfe4f0 1px solid;
}
.off-con-title{
  height: 55px;
  line-height: 55px;
  font-size: 18px;
  font-family: "PingFang SC";
  color: rgb(70, 69, 69);
  background-color: rgb(240, 234, 234);
  border-top-right-radius: 8%;
  border-top-left-radius: 8%;
  padding-left: 20px;
  margin-bottom: 10px;
  border-bottom: 1px solid rgb(221, 214, 214)
}
.off-con-content{
  padding: 10px 35px 0 35px;
}
.off-con-list{
  padding-bottom:20px;
  border-bottom: #dfe4f0 1px solid;
}
.off-con-button{
  line-height: 50px;
  float: right;
  padding: 0 45px 15px 0;
}
.off-con-title>i{
  position: absolute;
  top: 15px;
  right: 10px;
}
.off-con-title>i:hover{
  position: absolute;
  top: 15px;
  right: 10px;
  color: red;
  cursor: pointer;
}
.official-wechat-rate{
  width: 550px;
  position: absolute;
  top: 10%;
  left: 35%;
  border-radius: 1%;
  background-color: #F5F7FA
}
.weChat-model{
  width: 550px;
  position: absolute;
  top: 10%;
  left: 35%;
  border-radius: 1%;
  background-color: #F5F7FA
}
table{
  background-color: #FFF;
  width: 100%;
  font-size: 12px;
  min-width: 900px;
}
th{
  position: relative;
  word-wrap: normal;
  text-overflow: ellipsis;
  vertical-align: middle;
  border-bottom: 1px solid #ebeef5;
    
}
thead{
  padding: 8px 0;
  color: #909399;
}
tr{
  padding: 8px 0;
}
tr:hover{
  background-color: #F5F7FA;
}
td{
  border: none;
  border-bottom: 1px solid #ebeef5;
}
.table-cell{
  white-space: normal;
  word-break: break-all;
  line-height: 22px;
  padding: 10px 10px;
  text-align: center;
  min-width: 40px;
  box-sizing: border-box;
}
#span-channel-1{
  font-size: 16px;
}
#span-channel-2{
  font-size: 16px;
  color: rgb(40, 190, 103);
}
#span-channel-3,#span-channel-4{
  font-size: 14px;
  color: rgb(35, 158, 240);
  padding-right: 10px;
}
#span-rate{
  font-size: 12px;
  color: #626466;
  padding-left: 10px;

}
</style>